<template>
	<view class="auth">
		<view class="infos">
			<view class="list">
				<text>姓名</text>
				<input placeholder="请输入姓名"
					placeholderStyle="font-size: 28rpx;color: #999999;line-height: 40rpx;font-family: PingFangSC-Regular;"
					border="surround" v-model="detail.name"></input>
			</view>
			<view class="list">
				<text>身份证号码</text>
				<input placeholder="请输入身份证号码"
					placeholderStyle="font-size: 28rpx;color: #999999;line-height: 40rpx;font-family: PingFangSC-Regular;"
					border="surround" v-model="detail.idnum"></input>
			</view>
			<view class="list">
				<text>上传身份证正面</text>
				<view class="upload">
					<tn-image-upload :header="header" :formData="formData" :action="action" :fileList="back_img"
						:maxCount='1' @onSuccess="onSuccess" :index="0" @onUploaded="onUploaded">
					</tn-image-upload>
					<text>请保证身份证完整，身份证号清晰</text>
				</view>
			</view>
			<view class="list">
				<text>上传身份证反面</text>
				<view class="upload">
					<tn-image-upload :header="header" :formData="formData" :action="action" :fileList="positive_img"
						:maxCount='1' @onSuccess="onSuccess" :index="1" @onUploaded="onUploaded">
					</tn-image-upload>
					<text>请保证身份证完整，身份证号清晰</text>
				</view>
			</view>
			<view class="button" v-if="detail.status!=2">
				<text @click="btn">提交认证信息</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCardocrInfo,
		getCardocrApply
	} from "@/apis/index"
	import {
		getToken
	} from "@/util/auth"
	export default {
		data() {
			return {
				// 演示地址，请勿直接使用
				action: 'https://www.taoding1688.com/api/common/upload',
				header: {
					'token': getToken()
				},
				formData: {
					'group': 'ugc', // 其他要传的参数
				},
				back_img: [],
				positive_img: [],
				name: '',
				value: '',
				image: [],
				detail: {}
			}
		},
		created() {},
		onLoad() {
			this.getList()
		},
		methods: {
			getList() {
				getCardocrInfo().then(res => {
					if (res.code == 1) {
						this.detail = res.data
						this.back_img = [{
							url:this.info.app.cdnurl+res.data.back_img
						}]
						this.positive_img = [{
							url:this.info.app.cdnurl+res.data.positive_img
						}]
						console.log(this.back_img,this.positive_img)
					}
				})
			},
			async afterRead(event) {},
			onSuccess(data, index, list, indexs) {
				// if (index == 0) {
				// 	this.back_img = [data.data.url]
				// } else {
				// 	this.positive_img = [data.data.url]
				// }
				console.log(this.back_img,this.positive_img,'------------------------')

			},
			onUploaded(lists, name){
				console.log(lists, name)
				
				if (name == 1) {
					this.positive_img = lists[0].response.data.url
				} else {
					this.back_img = lists[0].response.data.url
				}
			},
			btn(){
				if (!this.detail.name) {
					uni.showToast({
						title:'请输入姓名',
						icon:'none'
					})
					return
				}
				if (!this.detail.idnum) {
					uni.showToast({
						title:'请输入身份证号码',
						icon:'none'
					})
					return
				}
				if (!this.positive_img) {
					uni.showToast({
						title:'请上传身份证正面',
						icon:'none'
					})
					return
				}
				if (!this.back_img) {
					uni.showToast({
						title:'请上传身份证反面',
						icon:'none'
					})
					return
				}
				let obj={
					name:this.detail.name,
					idnum:this.detail.idnum,
					positive_img:this.positive_img,
					back_img:this.back_img
				}
				console.log(obj)
				getCardocrApply(obj).then(res=>{
					if (res.code==1) {
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.auth {
		height: 100%;
		background-color: #FFFFFF;

		& text {
			font-family: PingFangSC-Regular, PingFang SC;
			color: #7C7597;
		}

		.infos {
			.list {
				display: flex;
				flex-direction: column;
				padding: 20rpx 60rpx 0;

				>text {
					font-size: 28rpx;
					font-weight: 600;
					color: #160651;
					line-height: 40rpx;
					margin-bottom: 14rpx;
				}

				>input {
					height: 80rpx;
					background: #F5F5FB;
					border-radius: 10rpx;
					padding-left: 32rpx;
				}

				.upload {
					display: flex;
					flex-direction: column;
					align-items: center;
					background: #F5F5FB;
					border-radius: 10rpx;
					padding: 62rpx 54rpx 30rpx 54rpx;

					& image {
						width: 488rpx;
						height: 264rpx;
					}

					>text {
						margin-top: 38rpx;
					}
				}
			}
		}

		.button {
			display: flex;
			padding: 0 82rpx;
			margin-top: 78rpx;

			>text {
				width: 100%;
				height: 84rpx;
				background: #533CD7;
				box-shadow: 0rpx 6rpx 30rpx 0rpx rgba(83, 60, 215, 0.4600);
				border-radius: 43rpx;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 84rpx;
				text-align: center;
			}
		}

		.text {
			width: 100%;
			display: flex;
			justify-content: center;
			margin-top: 10rpx;
		}
	}
</style>